package com.cy.comstore.common;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpSession;
import java.time.LocalDateTime;
import java.util.Date;

/*自定义元数据对象处理器*/
@Component //此注解表示 将其交给spring去管理
@Slf4j
public class MyMetaObjectHandler implements MetaObjectHandler {
   /* @Autowired
    HttpSession httpSession;*/
    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("公共字段自动填充[insert]...");
        metaObject.setValue("createdTime", new Date());
        metaObject.setValue("modifiedTime", new Date());
    }
       /* this.setFieldValByName("createdTime",new Date(),metaObject);
        this.setFieldValByName("modifiedTime",new Date(),metaObject);
    }*/

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("公共字段自动填充[update]...");
        log.info(metaObject.toString());
        metaObject.setValue("modifiedTime", new Date());
    }
}
